fix(crash): debug builds would not try to remove a not found job
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Fri, 6 Jun 2025 09:58:39 +0000 (11:58 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Wed, 18 Jun 2025 07:52:12 +0000 (07:52 +0000)
in release builds we would happily try to remove an element from QList
with invalid index (-1) if the job is not found

avoid doing this in release builds and keep teh assert in debug builds

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/libsync/owncloudpropagator.cpp

index bd597dee8df059582222d391fa9e98d0bf8acd50..fba85c539ca1609a70b728014ef1d089c7c18410 100644 (file)
@@ -1293,9 +1293,11 @@ void PropagatorCompositeJob::slotSubJobFinished(SyncFileItem::Status status)
 
     // Delete the job and remove it from our list of jobs.
     subJob->deleteLater();
-    int i = _runningJobs.indexOf(subJob);
-    Q_ASSERT(i >= 0); // should only happen if this function is called more than once
-    _runningJobs.remove(i);
+    const auto i = _runningJobs.indexOf(subJob);
+    Q_ASSERT(i >= 0 && i < _runningJobs.size()); // should only happen if this function is called more than once
+    if (i >= 0 && i < _runningJobs.size()) {
+        _runningJobs.remove(i);
+    }
 
     // Any sub job error will cause the whole composite to fail. This is important
     // for knowing whether to update the etag in PropagateDirectory, for example.